package com.shop.front.dao.article;


import com.shop.jpa.BaseSQLDao;
import com.shop.jpa.support.QuerySQL;
import com.shop.front.vo.article.ArticleInfoVo;
import com.shop.domain.article.Article;
import com.shop.web.context.WebContext;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Repository;

@Repository
public class ArticleSQLDao extends BaseSQLDao {

    /**
     * 分页查询公告信息
     * @return
     */
    public Page<Article> pageArticle() {
        StringBuffer field = new StringBuffer("u.*");
        String from = "t_article u";
        String order = "u.id desc";
        QuerySQL qs = new QuerySQL(WebContext.getPageNo(), WebContext.getPageSize(), field.toString(), from, order);
        qs.addWhereWithoutParams("u.is_deleted = 0 ");
        return this.page(qs, Article.class);
    }


    /**
     * 通过ID查询 公告详情
     * @param id
     * @return
     */
    public ArticleInfoVo queryArticleInfo(Long id){
        StringBuffer field = new StringBuffer("a.id,a.title,a.create_time,c.content");
        String from = "t_article a inner join t_article_content c on a.id=c.nid";
        QuerySQL qs = new QuerySQL(field.toString(), from, null);
        qs.addWhereEq("a.id", id);
        return this.querySingle(qs, ArticleInfoVo.class);
    }



}
